package com.vvv.shortlink.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vvv.shortlink.common.convention.result.Result;
import com.vvv.shortlink.common.convention.result.Results;
import com.vvv.shortlink.project.dto.req.RecycleBinPageReqDTO;
import com.vvv.shortlink.project.dto.req.RecycleBinRecoverReqDTO;
import com.vvv.shortlink.project.dto.req.RecycleBinRemoveReqDTO;
import com.vvv.shortlink.project.dto.req.RecycleBinSaveReqDTO;
import com.vvv.shortlink.project.dto.resp.LinkPageRespDTO;
import com.vvv.shortlink.project.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author vvv
 * @date 2024/2/19 14 52
 * discription
 */
@RestController
@RequiredArgsConstructor
public class RecycleBinController {

    private final RecycleBinService recycleBinService;

    /**
     * 将短链接移至回收站
     */
    @PostMapping("/api/short-link/v1/recycle-bin/save")
    public Result<Void> saveLinkToBin(@RequestBody RecycleBinSaveReqDTO requestParam) {
        recycleBinService.saveLinkToBin(requestParam);
        return Results.success();
    }

    /**
     * 分页查询回收站中的短链接
     */
    @GetMapping("/api/short-link/v1/recycle-bin/page")
    public Result<IPage<LinkPageRespDTO>> pageShortLinkInBin(RecycleBinPageReqDTO requestParam) {
        return Results.success(recycleBinService.pageShortLinkInBin(requestParam));
    }

    /**
     * 从回收站中恢复短链接
     */
    @PostMapping("/api/short-link/v1/recycle-bin/recover")
    public Result<Void> recoverShortLinkFromBin(@RequestBody RecycleBinRecoverReqDTO requestParam) {
        recycleBinService.recoverShortLink(requestParam);
        return Results.success();
    }

    /**
     * 从回收站中移除短链接
     */
    @PostMapping("/api/short-link/v1/recycle-bin/remove")
    public Result<Void> removeShortLinkFromBin(@RequestBody RecycleBinRemoveReqDTO requestParam) {
        recycleBinService.removeShortLinkFromBin(requestParam);
        return Results.success();
    }
}
